{% extends 'search_result.html' %}

{% block page_title %}{{ user.name }}的留言{% endblock page_title %}

{% block main_div %}
<div class="col-md-12">
{% if fromDB|length == 0 %}
    <div class="alert alert-danger" role="alert">您还没有发表的留言或保存笔记</div>
{% else %}
        {% if errormsg != None %}
        <div class="alert alert-danger" role="alert">{{ errormsg }}</div>
        {% endif %}
        {% for com in fromDB %}
        {% if com.note == 0 %}
            <div class="panel panel-primary">
                <div class="panel-heading"><b>您</b>在<a href="/tactic/?name={{ com.position.name }}&stru={{ com.position.structure.name }}" target="_blank" style="color: white;"> &lt{{ com.position.name }}<span class="glyphicon glyphicon-new-window"></span>&gt </a>的留言: 
                <div class="navbar-right"><a href="/comment/delete?id={{ com.id }}&t=c&url={{ request.get_full_path }}" style="color: white; margin-right: 20px;">删除 <span class="
                glyphicon glyphicon-trash"></span></a></div>
                <div class="navbar-right"><a href="/comment/statu_change?id={{ com.id }}&note=1&url={{ request.get_full_path }}" style="color: white; margin-right: 20px;">转存为笔记 <span class="glyphicon glyphicon-edit"></span></a></div>
            </div>
        {% else %}
            <div class="panel panel-warning">
            <div class="panel-heading"><b>您</b>在<a href="/tactic/?name={{ com.position.name }}&stru={{ com.position.structure.name }}" target="_blank" style="color: #8a6d3b;"> &lt{{ com.position.name }}<span class="glyphicon glyphicon-new-window"></span>&gt </a>保存的笔记: 
            <div class="navbar-right"><a href="/comment/delete?id={{ com.id }}&t=c&url={{ request.get_full_path }}" style="color: #8a6d3b; margin-right: 20px;">删除 <span class="
            glyphicon glyphicon-trash"></span></a></div>
            <div class="navbar-right"><a href="/comment/statu_change?id={{ com.id }}&note=0&url={{ request.get_full_path }}" style="color: #8a6d3b; margin-right: 20px;">发表为留言 <span class="glyphicon glyphicon-check"></span></a></div></div>
        {% endif %}
            <div class="panel-body">
                <div id="{{ com.id }}">
                    <!-- Server-side output Markdown text -->
                    <textarea style="display:none;">{{ com.content }}</textarea>
                </div>
                {% if com.replys|length != 0 %}
                <div class="col-md-10">
                    <table class="table">
                {% for reply in com.replys %}
                    <tr>
                        <td>{{ reply.content }} - <a href="/user/?uid={{ reply.user.uid }}">{{ reply.user.name }}</a> <small>{{ reply.time }}</small>{% if reply.user.uid == user.uid %} <a href="/comment/delete?id={{ reply.id }}&t=qr&url={{ request.get_full_path }}"><span class="glyphicon glyphicon-trash"></span></a> {% endif %}</td>
                    </tr>
                {% endfor %}
                    </table>
                </div>
                {% endif %}
            </div>
            <div class="panel-footer text-right">{{ com.time }}</div>
          </div>
          <script type="text/javascript">
            $(function() {
              var testView = editormd.markdownToHTML("{{ com.id }}", {
                    // markdown : "[TOC]\n### Hello world!\n## Heading 2", // Also, you can dynamic set Markdown text
                    // htmlDecode : true,  // Enable / disable HTML tag encode.
                    // htmlDecode : "style,script,iframe",  // Note: If enabled, you should filter some dangerous HTML tags for website security.
                });
            });
          </script>  
        {% endfor %}
{% endif %}
    <div style="text-align:center;">
        {% if pager.num_pages > 1 %}
        <nav aria-label="...">
            <ul class="pagination">
            {% if fromDB.has_previous %}
                <li><a href="?q={{ q }}{% if onlyshow != None %}onlyshow={{ onlyshow }}&{% endif %}&n={{ fromDB.previous_page_number }}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
            {% else %}
                <li class="disabled"><span aria-label="Previous"><span aria-hidden="true">&laquo;</span></span></li>
            {% endif %}
            {% for each in showpagerange %}
                {% if each == fromDB.number %}
                <li class="active"><span>{{ each }} <span class="sr-only">(current)</span></span></li>  
                {% else %}
                <li><a href="?q={{ q }}{% if onlyshow != None %}onlyshow={{ onlyshow }}&{% endif %}&n={{ each }}">{{ each }} <span class="sr-only">(current)</span></a></li>
                {% endif %}
            {% endfor %}
            {% if fromDB.has_next %}
                <li><a href="?q={{ q }}{% if onlyshow != None %}onlyshow={{ onlyshow }}&{% endif %}&n={{ fromDB.next_page_number }}" aria-label="Previous"><span aria-hidden="true">&raquo;</span></a></li>
            {% else %}
                <li class="disabled"><span aria-label="Previous"><span aria-hidden="true">&raquo;</span></span></li>
            {% endif %}
            </ul>
        </nav>
        {% endif %}
    </div>
</div>
      <script src="/static/editor.md/editormd.js"></script>
      <script src="/static/editor.md/lib/marked.min.js"></script>
      <script src="/static/editor.md/lib/prettify.min.js"></script>
{% endblock main_div %}